home *** CD-ROM | disk | FTP | other *** search
/ Eagles Nest BBS 8 / Eagles_Nest_Mac_Collection_Disc_8.TOAST / Developer Environments / TurPasDBTlbx / TP-Database Toolbox / BTree Sample / BTree.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1987-12-11  |  40.5 KB  |  1,347 lines  |  [TEXT/TPAS]

  1. (*********************************************************************)
  2. (*                  Turbo Pascal Database Toolbox                    *)
  3. (*                       For the Macintosh                           *)
  4. (*            Copyright (C) 1987 Borland International               *)
  5. (*                    Toolbox version: 1.0                           *)
  6. (*                                                                   *)
  7. (*              BTree - A Sample Customer Database                   *)
  8. (*                                                                   *)
  9. (*  Implements a database that has one data file and 2 index files.  *)
  10. (*  Unlike the simpler examples in the Access Samples folder, BTree  *)
  11. (*  displays a full-blown "Macintosh User Interface".                *)
  12. (*                                                                   *)
  13. (*********************************************************************)
  14.  
  15. (*********************************************************************)
  16. (*              BTree - Configuration for compilation                *)
  17. (*                                                                   *)
  18. (*    Follow these steps in order to compile BTree.pas:              *)
  19. (*                                                                   *)
  20. (*    1.  Copy TAccess.unit from the Turbo Access folder into the    *)
  21. (*        folder or disk that contains Btree.pas.                    *)
  22. (*                                                                   *)
  23. (*    2.  Bring the source for TAccess.unit into the Turbo Pascal    *)
  24. (*        integrated environment.                                    *)
  25. (*                                                                   *)
  26. (*    3.  Modify the $I include file directive to this syntax:       *)
  27. (*        {$I BTree.const}                                           *)
  28. (*                                                                   *)
  29. (*    4.  Compile TAccess.unit to disk.                              *)
  30. (*                                                                   *)
  31. (*    5.  Bring the BTreeTA.unit source into the Turbo Pascal        *)
  32. (*        environment and compile it to disk.                        *)
  33. (*                                                                   *)
  34. (*    6.  Bring the BTree.pas source file into the Turbo Pascal      *)
  35. (*        environment.                                               *)
  36. (*                                                                   *)
  37. (*    7.  Run BTree in memory or compile to disk.                    *)
  38. (*                                                                   *)
  39. (*    For further reference, see pages 34-39 of the Turbo Pascal     *)
  40. (*    Database Toolbox Owner's Handbook.                             *)
  41. (*                                                                   *)
  42. (*********************************************************************)
  43.  
  44. program BTree;
  45. {$U-}
  46. {$U TAccess}
  47. {$U BTreeTA}
  48. {$R BTree.rsrc}
  49. {$S+}
  50. uses
  51.  {If a compiler error occurs here, Turbo Pascal cannot find the TAccess
  52.   and BTreeTA units. You must first compile these units to this disk
  53.   (or folder if using HFS) before compiling Btree.  See the top of 
  54.   this file for detailed instructions.
  55.  }
  56. memtypes, 
  57. {$S QuickDraw} QuickDraw,
  58. {$S OSIntf} OSIntf,
  59. {$S ToolIntf} ToolIntf,PackIntf,PasInOut,
  60. {$S TAccess} TAccess,
  61. {$S BTreeTA} BTreeTA;
  62.  
  63. const
  64.   MenuCnt      = 5;
  65.   applMenuID   = 128;
  66.   fileMenuID   = 129;
  67.     quitItem   = 1;
  68.   editMenuID   = 130;
  69.     undoItem   = 1;
  70.     cutItem    = 3;
  71.     copyItem   = 4;
  72.     pasteItem  = 5;
  73.     clearItem  = 6;
  74.   dataMenuID   = 131;
  75.     AddRecItem = 1;
  76.     DelRecItem = 2;
  77.     ListVItem  = 4;
  78.   srchMenuID   = 132;
  79.     FirstItem  = 1;
  80.     LastItem   = 2;
  81.     NextItem   = 3;
  82.     PrevItem   = 4;
  83.     SOnItem    = 6;
  84.      
  85.   MenuStart   = applMenuID;
  86.     
  87.   srchDLogID       = 128;
  88.     FindExact      = 3;
  89.     LNameSearch    = 4;  
  90.     CustCodeSearch = 5;
  91.     SearchText     = 6;
  92.   entrDLogID       = 129;
  93.     OKButton       = 1;
  94.     CanButton      = 2;
  95.     CodeItem       = 4;
  96.     DateItem       = 6;
  97.     FNameItem      = 8;
  98.     LNameItem      = 10;
  99.     CompanyItem    = 12;
  100.     AddressItem    = 14;
  101.     CityItem       = 16;
  102.     StateItem      = 18;
  103.     ZipItem        = 20;
  104.     PhoneItem      = 22;
  105.     ExtensionItem  = 24;
  106.     
  107.   badDLogID       = 130;
  108.   
  109.   StringID        = 128;
  110.   aboutID         = 128;
  111.   
  112.   dupEntrErr      = 1;
  113.   noKeyErr        = 2;
  114.   
  115.   title1          = 'Turbo Pascal® DataBase Example 1.00';
  116.   title2          = '©1987 Borland International';
  117.  
  118.   returnKey       = 13;       { ASCII for return key }
  119.  
  120.   MaxCells        = 14;
  121.      recLength          = 11;
  122.      WindX1              = 250;
  123.      WindY1               = 125;
  124.      WindY2               = 268;
  125.     
  126. type
  127.     Buffer          = packed array[0..Maxint] of Char;
  128.     BufferPtr       = ^Buffer;
  129.     ProcPtr         = ^Integer;
  130.     
  131.     FileRec         = record
  132.                         fInpFlag:       Boolean;
  133.                         fOutFlag:       Boolean;
  134.                         fRefNum:        Integer;
  135.                         fVRefNum:       Integer;
  136.                         fBufSize:       Integer;
  137.                         fBufPos:        Integer;
  138.                         fBufEnd:        Integer;
  139.                         fBuffer:        BufferPtr;
  140.                         fInOutProc:     ProcPtr;
  141.                       end;
  142. Var
  143.     MenuList            : array[1..MenuCnt] of MenuHandle; { holds menu info }
  144.     entrDLog,srchDLog   : DialogPtr;
  145.     quit                : boolean;
  146.     brect               : Rect;
  147.     ENOKButtonHD,
  148.     SROKButtonHD,
  149.     LNameButtonHD,
  150.     CustCodeButtonHD,
  151.     FindEButtonHD,
  152.     FindTextHD          : ControlHandle;
  153.     temp                : integer;
  154.     SIndx               : ^IndexFile;
  155.     DLOGDirty           : Boolean;
  156.     OldKeyN             : String;
  157.     mcount1             : integer;
  158.     LView               : WindowPtr;
  159.     LArray              : Array[1..MaxCells] of longint;
  160.     LHScrollBar,
  161.        LVScrollBar            : ControlHandle;
  162.  
  163. procedure CleanUp;
  164. begin
  165.  CloseIndex(CodeIndx);
  166.  CloseIndex(NameIndx);
  167.  CloseFile(CustFile);
  168.  if Boolean(LView) then DisposeWindow(LView);
  169. end;
  170.  
  171. procedure Die;
  172. begin
  173.  CleanUp;
  174.  ExitToShell;
  175. end;
  176.  
  177. Var aboutBoxPtr : WindowPtr;
  178.     aboutIndex  : integer;
  179.  
  180. procedure DoAboutBox;
  181. var thisPort    : GrafPtr;
  182.     lineHight   : integer;
  183.     finfo       : FontInfo;
  184.     tempRect    : Rect;
  185.     LR,TB       : integer;
  186. begin
  187.  getPort(thisPort);
  188.  if aboutBoxPtr = Pointer(0) then 
  189.  begin
  190.   tempRect := screenBits.bounds;
  191.   with screenBits.bounds do InsetRect(tempRect,
  192.                                 (right-left) div 2 - (355 div 2),
  193.                                 (bottom-top) div 2 - (85 div 2));
  194.   aboutBoxPtr := NewWindow(nil,tempRect,'',False,2,Pointer(-1),false,0);
  195.   setport(aboutBoxPtr);
  196.   ShowWindow(aboutBoxPtr);
  197.   with thePort^.portRect do
  198.    begin
  199.     ForeColor(WhiteColor);
  200.     PaintRect(thePort^.portRect);
  201.     TextFont(geneva);
  202.     TextFace([Bold]);
  203.     TextSize(10);
  204.     GetFontInfo(finfo);
  205.     ForeColor(RedColor);
  206.     with finfo do linehight := ascent+descent+leading;
  207.     LR := (right-left) div 2;
  208.     TB := (bottom-top) div 2;
  209.     moveto(LR - (StringWidth(title1) div 2),
  210.            TB - linehight);
  211.     DrawString(title1);
  212.     moveto(LR - (StringWidth(title2) div 2),
  213.            TB);
  214.     DrawString(title2);
  215.    end;
  216.  end;
  217.  aboutIndex := aboutIndex + 1;
  218.  ForeColor(BlackColor);
  219.  setport(thisPort);
  220. end;
  221.  
  222. procedure KillAbout;
  223. begin
  224.  aboutIndex := 0;
  225.  DisposeWindow(aboutBoxPtr);
  226.  aboutBoxPtr := Pointer(0);
  227. end;
  228.  
  229. function KeyFromName(LastNm : String; FirstNm : String) : String;
  230. const
  231.   Blanks  =  '               ';
  232. begin
  233.   KeyFromName := UpcaseStr(LastNm) + 
  234.                  Copy(Blanks,1,15 - Length(LastNm)) +
  235.                  UpcaseStr(FirstNm);
  236. end;
  237.  
  238. procedure AddRecord;
  239. var tempString  : String;
  240.     tempRec     : CustRec;
  241.     CurItem     : integer;
  242.     itemType    : integer;
  243.     item        : Handle;
  244.     box         : Rect;
  245.     dateTime    : Longint;
  246.     
  247. begin
  248.  OldKeyN := '';
  249.  TempString := '';
  250.  with tempRec do
  251.  begin
  252.    CurItem := CodeItem;
  253.    repeat
  254.      GetDItem(entrDLog, CurItem, itemType, item , box);
  255.      SetIText(item, TempString);
  256.      CurItem := CurItem + 2;
  257.    until CurItem > ExtensionItem;
  258.  end;
  259.  GetDateTime(dateTime);
  260.  IUDateString(dateTime,shortDate,TempString);
  261.  GetDItem(entrDLog, DateItem, itemType, item , box);
  262.  SetIText(item, TempString);
  263.  SelIText(entrDLog, FNameItem, 0, 1);
  264. end;
  265.  
  266. procedure DelRecord;
  267. var tempCode,
  268.     tempFirstName,
  269.     tempLastName,
  270.     KeyN        : Str255;
  271.     tempRec     : CustRec;
  272.     itemType    : integer;
  273.     item        : Handle;
  274.     box         : Rect;
  275.     DataF,
  276.     tempL       : Longint;
  277.     
  278. begin
  279.  GetDItem(entrDLog, CodeItem, itemType, item , box);
  280.  GetIText(item,tempCode);
  281.  GetDItem(entrDLog, FNameItem, itemType, item , box);
  282.  GetIText(item,tempFirstName);
  283.  GetDItem(entrDLog, LNameItem, itemType, item , box);
  284.  GetIText(item,tempLastName);
  285.  StringToNum(tempCode,tempL);
  286.  tempCode := LongToStr(tempL);
  287.  FindKey(CodeIndx, DataF, tempCode);
  288.  if OK then 
  289.   begin
  290.    DeleteRec(CustFile,DataF);
  291.    KeyN := KeyFromName(tempLastName,tempFirstName); 
  292.    DeleteKey(NameIndx,DataF,KeyN);
  293.    DeleteKey(CodeIndx,DataF,tempCode);
  294.    AddRecord;
  295.   end
  296.  else
  297.   SysBeep(10);
  298. end;
  299.  
  300. procedure UpDateRecordOnDLOG(tempRec: CustRec);
  301. var tempString  : String;
  302.     CurItem     : integer;
  303.     itemType    : integer;
  304.     item        : Handle;
  305.     box         : Rect;
  306.     
  307. begin
  308.  SelectWindow(entrDLog);
  309.  TempString := '';
  310.  with tempRec do
  311.  begin
  312.    CurItem := CodeItem;
  313.    repeat
  314.      GetDItem(entrDLog, CurItem, itemType, item , box);
  315.      case CurItem of
  316.        CodeItem     : NumToString(CustCode,TempString);
  317.        DateItem     : TempString := Date;
  318.        FNameItem    : TempString := FName;
  319.        LNameItem    : TempString := LName;
  320.        CompanyItem  : TempString := Company;
  321.        AddressItem  : TempString := Address;
  322.        CityItem     : TempString := City;
  323.        StateItem    : TempString := State;
  324.        ZipItem      : TempString := Zip;
  325.        PhoneItem    : TempString := Phone;
  326.        ExtensionItem: TempString := Extension;
  327.      end;
  328.      SetIText(item, TempString);
  329.      CurItem := CurItem + 2;
  330.    until CurItem > ExtensionItem;
  331.    OldKeyN := KeyFromName(LName,FName);
  332.  end;
  333. end;
  334.  
  335. procedure HitOK; forward;
  336.  
  337. procedure DoFirstSearch;
  338. var tempKey     : String;
  339.     tempRecNum  : Longint;
  340.     tempRec     : CustRec;
  341. begin
  342.  ClearKey(SIndx^);
  343.  NextKey(SIndx^, tempRecNum, TempKey);
  344.  if OK then begin
  345.               HitOk;
  346.               GetRec(CustFile,tempRecNum,tempRec);
  347.               UpDateRecordOnDLOG(tempRec);
  348.             end;
  349. end;
  350.  
  351.  
  352. procedure DoLastSearch;
  353. var tempKey     : String;
  354.     tempRecNum  : Longint;
  355.     tempRec     : CustRec;
  356. begin
  357.  ClearKey(SIndx^);
  358.  PrevKey(SIndx^, tempRecNum, TempKey);
  359.  if OK then begin
  360.               HitOk;
  361.               GetRec(CustFile,tempRecNum,tempRec);
  362.               UpDateRecordOnDLOG(tempRec);
  363.             end;
  364. end;
  365.  
  366. procedure DoNextSearch;
  367. var tempKey     : String;
  368.     tempRecNum  : Longint;
  369.     tempRec     : CustRec;
  370. begin
  371.   repeat
  372.     NextKey(SIndx^, tempRecNum, TempKey);
  373.   until OK;
  374.   HitOk;
  375.   GetRec(CustFile,tempRecNum,tempRec);
  376.   UpDateRecordOnDLOG(tempRec);
  377. end;
  378.  
  379. procedure DoPrevSearch;
  380. var tempKey     : String;
  381.     tempRecNum  : Longint;
  382.     tempRec     : CustRec;
  383. begin
  384.   repeat
  385.      PrevKey(SIndx^, tempRecNum, TempKey);
  386.   until OK;
  387.   HitOk;
  388.   GetRec(CustFile,tempRecNum,tempRec);
  389.   UpDateRecordOnDLOG(tempRec);
  390. end;
  391.  
  392. procedure DoSearchOn;
  393. begin
  394.  SelectWindow(srchDLog);
  395. end;
  396.  
  397. procedure BadEntry(theErr : integer);
  398. var tempDPtr : DialogPtr;
  399.     tempStr  : Str255;
  400.     temp     : integer;
  401. begin
  402.  GetIndString(tempStr,StringID,theErr);
  403.  paramtext(tempStr,'','','');
  404.  tempDPtr := GetNewDialog(badDLogID,nil,Pointer(-1));
  405.  ModalDialog(nil,temp);
  406.  DisposDialog(tempDPtr);
  407. end;
  408.  
  409. procedure CopyRecFromDLOG(Var tempRec : CustRec);
  410. var TempString  : Str255;
  411.     itemhit     : integer;
  412.     itype       : integer;
  413.     itemHandle  : Handle;
  414.     box         : rect;
  415. begin
  416.  itemhit := CodeItem;
  417.  repeat
  418.   GetDItem(entrDLog, ItemHit, IType, ItemHandle , box);
  419.   GetIText(ItemHandle, TempString);
  420.      with tempRec do
  421.        case ItemHit of 
  422.          CodeItem       : StringToNum(TempString,CustCode);
  423.          DateItem       : Date      := TempString;
  424.          FNameItem      : FName     := TempString;
  425.          LNameItem      : LName     := TempString;
  426.          CompanyItem    : Company   := TempString;
  427.          AddressItem    : Address   := TempString;
  428.          CityItem       : City      := TempString;
  429.          StateItem      : State     := TempString;
  430.          ZipItem        : Zip       := TempString;
  431.          PhoneItem      : Phone     := TempString;
  432.          ExtensionItem  : Extension := TempString;
  433.          otherwise ;
  434.       end;
  435.   itemHit := itemHit + 2;
  436.  until (itemHit > ExtensionItem);
  437. end;
  438.  
  439.  
  440. const
  441.  CellSizeX = 123;
  442.  CellSizeY = 18; 
  443.  
  444. procedure ListView;
  445. Var    wName           : Str255;
  446.         r,
  447.         rv,
  448.         dv              : Rect;
  449.         p               : point;
  450.         tempKey        : String;
  451.         tempRecNum    : Longint;
  452.         tempRec        : CustRec;
  453.         x                : integer;
  454. begin
  455.  if Not Boolean(LView) then
  456.   begin
  457.    GetItem(MenuList[4],ListVItem,wName);
  458.    r := screenBits.bounds;
  459.    with r do 
  460.     begin
  461.      Top := ((Top + bottom) div 2) - WindY1;
  462.      left := ((Right + Left) div 2) - WindX1;
  463.      right := left + CellSizeX*4 + 16;
  464.      bottom := top + WindY2;
  465.     end;
  466.    p.h := 150;
  467.    p.v := 0;
  468.    LView := NewWindow(nil,r,wName,True,0,Pointer(-1),True,0);
  469.     GlobalToLocal(r.botRight);
  470.     r.top     := WindY2-16;
  471.     r.bottom := WindY2;
  472.     r.left     := 0;
  473.     r.right     := CellSizeX*4;
  474.     LHScrollBar := NewControl(LView,r,'',true,0,0,recLength*CellSizeX-(4*CellSizeX),scrollBarProc,0);
  475.     r.top     := 0;
  476.     r.bottom := WindY2-16;
  477.     r.left     := CellSizeX*4;
  478.     r.right     := CellSizeX*4+16; 
  479.     LVScrollBar := NewControl(LView,r,'',true,1,1,UsedRecs(CustFile)-MaxCells,scrollBarProc,0);
  480. (* Build the List Array *)
  481.  for x := 1 to MaxCells do
  482.    LArray[x] := -1;
  483.    
  484.    ClearKey(CodeIndx);
  485.    x := 1;
  486.    while Ok and (x <= MaxCells) do
  487.    begin
  488.         NextKey(CodeIndx, tempRecNum, TempKey);
  489.         if OK then 
  490.      begin
  491.        LArray[x] := tempRecNum;
  492.        x := succ(x);
  493.      end;
  494.       end;
  495.  end
  496.  else
  497.   SelectWindow(LView);
  498. end;
  499.  
  500. procedure LDrawWindow;
  501. var    x             : integer;
  502.         thisPort : GrafPtr;
  503.         r             : rect;
  504.  
  505.     (* DrawLine will Draw Line #line. It will know where to draw it *)
  506.     procedure DrawLine(line : integer);
  507.  Var    r                 : rect;
  508.         y1             : integer;
  509.         s              : String;
  510.         cust             : CustRec;
  511.         tempKey     : String;
  512.         tempRecNum  : Longint;
  513.         x,ct             : integer;
  514.     begin
  515.         if (LArray[line] <> -1) then 
  516.         begin
  517.             tempKey := LongToStr(LArray[line]);
  518.             FindKey(CodeIndx, tempRecNum, tempKey);
  519.             if OK then
  520.             with cust do
  521.              begin
  522.                 GetRec(CustFile,tempRecNum,cust);
  523.                 y1 := ((line-1)*CellSizeY)+14;
  524.                 ct := GetCtlValue(LHScrollBar);
  525.                 for x := 1 to recLength do
  526.                 begin
  527.                     SetRect(r,CellSizeX*(x-1)-ct,y1-14,CellSizeX*x+1-ct,y1+CellSizeY-14);
  528.                     EraseRect(r);
  529.                     FrameRect(r);
  530.                     moveto(CellSizeX*(x-1)+2-ct,y1-3);
  531.                     case x of 
  532.                     1: begin NumToString(LArray[line],s); DrawString(s); end;
  533.                     2: DrawString(Date);
  534.                     3: DrawString(FName);
  535.                     4: DrawString(LName);
  536.                     5: DrawString(Company);
  537.                     6: DrawString(Address);
  538.                     7: DrawString(City);
  539.                     8: DrawString(State);
  540.                     9: DrawString(Zip);
  541.                   10: DrawString(Phone);
  542.                   11: DrawString(Extension);
  543.                  end;
  544.                 end;
  545.              end;
  546.         end
  547.       else
  548.        begin
  549.             y1 := ((line-1)*CellSizeY)+14;
  550.             ct := GetCtlValue(LHScrollBar);
  551.             for x := 1 to recLength do
  552.             begin
  553.                 SetRect(r,CellSizeX*(x-1)-ct,y1-14,CellSizeX*x+1-ct,y1+CellSizeY-14);
  554.                 EraseRect(r);
  555.                 FrameRect(r);
  556.                 moveto(CellSizeX*(x-1)+2-ct,y1-3);
  557.             end;
  558.         end;
  559.     end;
  560.     
  561. begin (* LDrawWindow *)
  562.  GetPort(thisPort);
  563.  SetPort(LView);
  564.  BeginUpDate(LView);
  565.     r.top     := 0;
  566.     r.bottom := WindY2-16;
  567.     r.right     := CellSizeX*4;
  568.     r.left    := 0;
  569.     RectRgn(LView^.clipRgn,r);
  570.     for x := 1 to MaxCells do DrawLine(x);
  571.     r.top     := 0;
  572.     r.bottom := WindY2;
  573.     r.right     := CellSizeX*4+16;
  574.     r.left    := 0;
  575.     RectRgn(LView^.clipRgn,r);
  576.     DrawControls(LView);
  577.  EndUpDate(LView);
  578.  SetPort(thisPort);
  579. end; (* LDrawWindow *)
  580.  
  581. procedure NextEntry(many : integer);
  582. var     x             : integer;
  583.          r             : rect;
  584.         tempCode    : Str255;
  585.         DataF        : longint;
  586.         LifeOK    : Boolean;
  587. begin
  588.     if LArray[MaxCells] = -1 then exit;
  589.     x := 1;
  590.     if many = 1 then for x := 1 to MaxCells-many do LArray[x] := LArray[x+1];
  591.     if many = MaxCells-1 then LArray[1] := LArray[MaxCells];
  592.    tempCode := LongToStr(LArray[x]);
  593.    FindKey(CodeIndx, DataF, tempCode);
  594.     LifeOK := True;
  595.     for x := MaxCells-many+1 to MaxCells do
  596.     begin
  597.      if LifeOK then
  598.       begin
  599.          NextKey(CodeIndx, DataF, tempCode);
  600.          if OK then LArray[x] := DataF
  601.                   else begin
  602.                           LArray[x] := -1;
  603.                          LifeOK := False;
  604.                         end;
  605.       end
  606.      else 
  607.       LArray[x] := -1;
  608.     end;
  609.     r := LView^.portRect;
  610.     r.bottom := r.bottom-16;
  611.     r.right := r.right-16;
  612.     InvalRect(r);
  613.     LDrawWindow;    
  614. end;
  615.  
  616. procedure PrevEntry(many : integer);
  617. var     x,y        : integer;
  618.          r             : rect;
  619.         tempCode    : Str255;
  620.         DataF        : longint;
  621.         LifeOK    : Boolean;
  622. begin
  623.     for y := 1 to many do
  624.         for x := MaxCells downto 1 do LArray[x] := LArray[x-1];
  625.    tempCode := LongToStr(LArray[many+1]);
  626.    FindKey(CodeIndx, DataF, tempCode);
  627.     LifeOK := OK;
  628.     for x := many downto 1 do
  629.     begin
  630.      if LifeOK then
  631.       begin
  632.          PrevKey(CodeIndx, DataF, tempCode);
  633.          if OK then LArray[x] := DataF
  634.                   else begin
  635.                          LifeOK := False;
  636.                         end;
  637.       end
  638.      else 
  639.     end;
  640.     r := LView^.portRect;
  641.     r.bottom := r.bottom-16;
  642.     r.right := r.right-16;
  643.     InvalRect(r);
  644.     LDrawWindow;    
  645. end;
  646.  
  647. procedure LHScrollControl(theControl: ControlHandle; partCode: integer);
  648. var    r: rect;
  649. begin
  650.  case partCode of
  651.   inUpButton:         SetCtlValue(theControl,GetCtlValue(theControl)-10);
  652.   inDownButton:     SetCtlValue(theControl,GetCtlValue(theControl)+10);
  653.   inPageUp:            begin
  654.                            if (GetCtlValue(theControl)-CellSizeX) <> 0 then
  655.                               SetCtlValue(theControl,((GetCtlValue(theControl)-CellSizeX) div CellSizeX)*CellSizeX)
  656.                          else
  657.                            SetCtlValue(theControl,0);
  658.                         end;
  659.   inPageDown:         begin
  660.                         if (GetCtlValue(theControl)+CellSizeX) <> 0 then
  661.                             SetCtlValue(theControl,((GetCtlValue(theControl)+CellSizeX) div CellSizeX)*CellSizeX)
  662.                          else
  663.                           SetCtlValue(theControl,CellSizeX);
  664.                         end;
  665.                          
  666.  end;
  667.  if GetCtlValue(theControl) < 0 then SetCtlValue(theControl,0);
  668.  if (theControl = LHScrollBar) and (GetCtlValue(theControl) > recLength*CellSizeX) 
  669.      then SetCtlValue(theControl,recLength*CellSizeX);
  670.  r := LView^.portRect;
  671.  r.bottom := r.bottom-16;
  672.  r.right := r.right-16;
  673.  InvalRect(r);
  674.  LDrawWindow;    
  675. end;
  676.  
  677. procedure LVScrollControl(theControl: ControlHandle; partCode: integer);
  678. var    r: rect;
  679. begin
  680.  case partCode of
  681.   inUpButton:         begin
  682.                            if GetCtlValue(theControl) > 1 then
  683.                           begin
  684.                            PrevEntry(1);
  685.                            SetCtlValue(theControl,GetCtlValue(theControl)-1);
  686.                           end;
  687.                         end;
  688.   inDownButton:     begin
  689.                            if GetCtlValue(theControl)+1 > UsedRecs(CustFile)then 
  690.                           begin
  691.                            end
  692.                          else
  693.                           begin
  694.                              SetCtlValue(theControl,GetCtlValue(theControl)+1);
  695.                            NextEntry(1);
  696.                           end;
  697.                         end;
  698.   inPageUp:            begin
  699.                           if (GetCtlValue(theControl)-MaxCells-1 < 1) and
  700.                               (GetCtlValue(theControl) <> 1)
  701.                          then begin
  702.                                  PrevEntry(GetCtlValue(theControl)-1);
  703.                                 SetCtlValue(theControl,1);
  704.                               end
  705.                          else begin
  706.                                 SetCtlValue(theControl,GetCtlValue(theControl)-MaxCells-1);
  707.                                PrevEntry(MaxCells-1);
  708.                               end;
  709.                         end;
  710.   inPageDown:         begin
  711.                            if GetCtlValue(theControl)+MaxCells-1 > UsedRecs(CustFile) 
  712.                           then begin
  713.                                   NextEntry(UsedRecs(CustFile)-GetCtlValue(theControl));
  714.                                     SetCtlValue(theControl,UsedRecs(CustFile));
  715.                                  end
  716.                           else begin
  717.                                      SetCtlValue(theControl,GetCtlValue(theControl)+MaxCells-1);
  718.                                    NextEntry(MaxCells-1);
  719.                                  end;
  720.                         end;
  721.                          
  722.  end;
  723.  if GetCtlValue(theControl) < 1 then SetCtlValue(theControl,1);
  724.  if (theControl = LVScrollBar) and (GetCtlValue(theControl) > UsedRecs(CustFile)) 
  725.      then SetCtlValue(theControl,UsedRecs(CustFile));
  726.  r := LView^.portRect;
  727.  r.bottom := r.bottom-16;
  728.  r.right := r.right-16;
  729.  InvalRect(r);
  730.  LDrawWindow;    
  731. end;
  732.  
  733. procedure HitOK;
  734. Var tempRec : CustRec;
  735.     DataF   : Longint;
  736.     KeyN    : String[25];
  737.     tempSPtr: StringPtr;
  738.     tempCode: Longint;
  739.     tempStr : String;
  740.     tempLS  : LongIntStr;
  741.  
  742. begin (* HitOK *)
  743. if DLOGDirty then 
  744.  begin
  745.   CopyRecFromDLog(tempRec);
  746.   with tempRec do
  747.   begin
  748.     if CustCode <> 0 then 
  749.     begin
  750.       tempStr := LongToStr(CustCode);
  751.       FindKey(CodeIndx, DataF, tempStr);
  752.       if OK then
  753.       begin
  754.          PutRec(CustFile, DataF, tempRec);
  755.          KeyN := KeyFromName(LName,FName);
  756.          if OldKeyN <> KeyN then 
  757.          begin
  758.            { Remove it if it was already there }
  759.            DeleteKey(NameIndx, DataF, OldKeyN);   
  760.            AddKey(NameIndx, DataF, KeyN); 
  761.          end;
  762.       end;
  763.      end
  764.      else
  765.        if (LName <> '') and (FName <> '') then
  766.        begin
  767.           KeyN := KeyFromName(LName,FName);
  768.           begin
  769.            AddRec(CustFile, DataF, tempRec);
  770.            tempLS := LongToStr(DataF);
  771.            CustCode := DataF;
  772.            PutRec(CustFile, DataF, tempRec);
  773.            AddKey(CodeIndx, DataF, tempLS);
  774.            KeyN := KeyFromName(LName,FName);
  775.            AddKey(NameIndx, DataF, KeyN); 
  776.            UpDateRecordOnDLOG(tempRec);
  777.            AddRecord;
  778.          end
  779.        end
  780.        else
  781.          BadEntry(noKeyErr);
  782.      DLOGDirty := False;
  783.    end; { with }
  784.  end; { if }
  785. end; (* HitOK *)
  786.  
  787. procedure HitSearchBox(itemHit : integer);
  788.  
  789.     procedure Find;
  790.     var tempKey,
  791.         tempText : Str255;
  792.         DataF,
  793.         tempL    : longint;
  794.         tempRec  : CustRec;
  795.         tempK    : LongIntStr;
  796.     begin
  797.      GetIText(Handle(FindTextHD),tempText);
  798.      tempText := UpCaseStr(tempText);
  799.      tempKey := tempText;
  800.      if SIndx = @NameIndx then
  801.       begin                                 (* Find on name *)
  802.        if (Boolean(GetCtlValue(FindEButtonHD))) then tempText := tempText + ' ';
  803.        SearchKey(SIndx^,DataF, tempKey);
  804.        if (OK) and (Pos(tempText,tempKey) = 1) then 
  805.         begin
  806.           GetRec(CustFile,DataF,tempRec);
  807.           HitOK;                               (* save old entry in Dialog *)
  808.           UpDateRecordOnDLOG(tempRec);
  809.         end
  810.        else SysBeep(10);
  811.       end
  812.      else
  813.       begin                                 (* Find on Cust Code*)
  814.        StringToNum(tempKey,tempL);
  815.        tempK := LongToStr(tempL);
  816.        FindKey(SIndx^,DataF, tempK);
  817.        if OK then 
  818.         begin
  819.          GetRec(CustFile,DataF,tempRec);
  820.          HitOK;                               (* save old entry in Dialog *)
  821.          UpDateRecordOnDLOG(tempRec);
  822.         end
  823.        else SysBeep(10);
  824.       end;
  825.     end;
  826.     
  827. begin
  828.  case itemHit of
  829.   FindExact     : SetCtlValue(FindEButtonHD,(GetCtlValue(FindEButtonHD)+1) and 1);
  830.   OKButton      : Find;
  831.   CanButton     : ;
  832.   LNameSearch   : begin
  833.                    SetCtlValue(LNameButtonHD,1);
  834.                    SetCtlValue(CustCodeButtonHD,0);
  835.                    SIndx := @NameIndx;
  836.                    HiliteControl(FindEButtonHD,0);
  837.                  end;
  838.   CustCodeSearch: begin
  839.                    SetCtlValue(LNameButtonHD,0);
  840.                    SetCtlValue(CustCodeButtonHD,1);
  841.                    SIndx := @CodeIndx;
  842.                    HiliteControl(FindEButtonHD,255);
  843.                   end;
  844.  end;
  845. end;
  846.  
  847. var event       : EventRecord;
  848.     whichDlog   : DialogPtr;
  849.     wItemHit    : integer;
  850.  
  851.     procedure CheckMenus;
  852.     Var currentRec  : CustRec;
  853.         err         : integer;
  854.         f           : ^FileRec;
  855.         wind        : WindowPeek;
  856.     begin
  857.      CopyRecFromDLog(currentRec);
  858.       if FrontWindow = entrDLog then 
  859.        begin
  860.           if currentRec.CustCode <= 0 then DisableItem(MenuList[4],DelRecItem)
  861.                                               else EnableItem(MenuList[4],DelRecItem);
  862.         end
  863.       else
  864.        DisableItem(MenuList[4],DelRecItem);
  865.       wind := WindowPeek(FrontWindow);
  866.      if wind <> WindowPeek(0) then
  867.       if (wind^.windowKind < 0) then begin
  868.                                       EnableItem(MenuList[3],undoItem);
  869.                                       DisableItem(MenuList[2],0);
  870.                                       DisableItem(MenuList[4],0);
  871.                                       DisableItem(MenuList[5],0);
  872.                                       if BitAnd(mcount1,$4000)=0 then DrawMenuBar;
  873.                                       BitSet(@mcount1,1);
  874.                                      end
  875.                                 else begin
  876.                                       DisableItem(MenuList[3],undoItem);
  877.                                       EnableItem(MenuList[2],0);
  878.                                       EnableItem(MenuList[4],0);
  879.                                       EnableItem(MenuList[5],0);
  880.                                                                       
  881.                                       if UsedRecs(CustFile) = 0 then
  882.                                        begin
  883.                                         DisableItem(MenuList[5],0);
  884.                                         if not BitTst(@mcount1,0) then DrawMenuBar;
  885.                                         BitSet(@mcount1,0);
  886.                                        end
  887.                                       else
  888.                                        begin
  889.                                         if BitTst(@mcount1,0) then DrawMenuBar;
  890.                                         BitClr(@mcount1,0);
  891.                                        end;
  892.                                       
  893.                                       if BitAnd(mcount1,$4000)>0 then DrawMenuBar;
  894.                                       BitClr(@mcount1,1);
  895.                                      end;
  896.  
  897.     end;
  898.     
  899.     function TextToStr(h : Handle; offset1,offset2 : Longint) : Str255;
  900.     var temp    : Longint;
  901.         x       : integer;
  902.         c       : char;
  903.         s       : str255;
  904.         p       : Ptr;
  905.     begin
  906.      s := '';
  907.      HLock(h);
  908.      p := Ptr(longint(h^) + offset1);
  909.      for x := 0 to offset2-offset1-1 do
  910.       begin
  911.        s := s + char(p^);
  912.        p := ptr(longint(p) + 1);
  913.       end;
  914.      HUnLock(h);
  915.      TextToStr := s;
  916.     end;
  917.     
  918.     procedure DoMenu(key : Boolean);
  919.     var x,templ     : longint;
  920.         mItem       : integer;
  921.         temp        : integer;
  922.         thisPort    : GrafPtr;
  923.         tempStr     : Str255;
  924.         hte         : TEHandle;
  925.         tempR       : Rect;
  926.         Cust        : CustRec;
  927.         textlength  : integer;
  928.         scrapSize,
  929.         offset1,
  930.         offset2     : longint;
  931.         hDest       : Handle;
  932.         searchChar  : integer;
  933.         CurrentEItem: integer;
  934.         item        : Handle;
  935.         ItemType    : integer;
  936.         box         : Rect;
  937.         
  938.     begin
  939.      if Key then x := MenuKey(char(event.message and charCodeMask))
  940.             else x := MenuSelect(event.where);
  941.      mItem := LoWord(x);
  942.      case HiWord(x) of
  943.         applMenuID : if mItem > 2 then
  944.                       begin
  945.                        GetPort(thisPort);
  946.                        GetItem(MenuList[applMenuID-menuStart+1],mItem,tempStr);
  947.                        temp := OpenDeskAcc(tempStr);
  948.                        SetPort(thisPort);
  949.                       end
  950.                      else
  951.                       begin
  952.                        repeat 
  953.                         DoAboutBox;
  954.                        until GetNextEvent(mouseDown+keyDown,event);
  955.                        FlushEvents(everyEvent,0);
  956.                        KillAbout;
  957.                       end;
  958.                       
  959.         fileMenuID : case mItem of
  960.                       quitItem : begin
  961.                                    HitOk;
  962.                                    quit := true;
  963.                                  end;
  964.                      end; (* case *)
  965.         editMenuID : if not SystemEdit(mItem-1) then
  966.                       case mItem of
  967.                        undoItem : ;
  968.                        cutItem  : begin
  969.                                    DlgCut(FrontWindow);
  970.                                    templ := TEToScrap;
  971.                                   end;
  972.                        copyItem : begin
  973.                                    if Boolean(event.modifiers and optionKey) then
  974.                                     with Cust do
  975.                                      begin
  976.                                       CopyRecFromDLOG(Cust);
  977.                                       SetRect(tempR,0,0,1,1);
  978.                                       hTE := TENew(tempR,tempR);
  979.                                       textLength := 0;
  980.                                       
  981.                                       TEInsert(ptr(Longint(@FName)+1),Length(FName),hTE);
  982.                                       TEKey(^I,hTE);
  983.                                       textlength := textlength + Length(FName)+1;
  984.                                       
  985.                                       TEInsert(ptr(Longint(@LName)+1),Length(LName),hTE);
  986.                                       TEKey(^I,hTE);
  987.                                       textlength := textlength + Length(LName)+1;
  988.                                       
  989.                                       TEInsert(ptr(Longint(@Company)+1),Length(Company),hTE);
  990.                                       TEKey(^I,hTE);
  991.                                       textlength := textlength + Length(Company)+1;
  992.                                       
  993.                                       TEInsert(ptr(Longint(@Address)+1),Length(Address),hTE);
  994.                                       TEKey(^I,hTE);
  995.                                       textlength := textlength + Length(Address)+1;
  996.                                       
  997.                                       TEInsert(ptr(Longint(@City)+1),Length(City),hTE);
  998.                                       TEKey(^I,hTE);
  999.                                       textlength := textlength + Length(City)+1;
  1000.                                       
  1001.                                       TEInsert(ptr(Longint(@State)+1),Length(State),hTE);
  1002.                                       TEKey(^I,hTE);
  1003.                                       textlength := textlength + Length(State)+1;
  1004.                                       
  1005.                                       TEInsert(ptr(Longint(@Zip)+1),Length(Zip),hTE);
  1006.                                       TEKey(^I,hTE);
  1007.                                       textlength := textlength + Length(Zip)+1;
  1008.                                       
  1009.                                       TEInsert(ptr(Longint(@Phone)+1),Length(Phone),hTE);
  1010.                                       TEKey(^I,hTE);
  1011.                                       textlength := textlength + Length(Phone)+1;
  1012.                                       
  1013.                                       TEInsert(ptr(Longint(@Extension)+1),Length(Extension),hTE);
  1014.                                       TEKey(^I,hTE);
  1015.                                       textlength := textlength + Length(Extension)+1;
  1016.                                       
  1017.                                       TESetSelect(0,textlength,hTE);
  1018.                                       TECopy(hTE);
  1019.                                       templ := TEToScrap;
  1020.                                       TEDispose(hTE);
  1021.                                      end
  1022.                                     else
  1023.                                      begin
  1024.                                       DlgCopy(FrontWindow);
  1025.                                       templ := TEToScrap;
  1026.                                      end;
  1027.                                   end;
  1028.                        pasteItem: begin
  1029.                                    HitOK;
  1030.                                    hDest := NewHandle(0);
  1031.                                    searchChar := $0900;
  1032.                                    CurrentEItem := DialogPeek(entrDLOg)^.editField+1;
  1033.                                    scrapSize := GetScrap(hDest,'TEXT',offset1);
  1034.                                    offset1 := 0;
  1035.                                    if Boolean(scrapSize) then
  1036.                                     begin
  1037.                                      AddRecord;
  1038.                                      DLOGDirty := True;
  1039.                                      repeat
  1040.                                       offset2 := Munger(hDest,offset1,
  1041.                                                        @searchChar,1,
  1042.                                                        Nil,0);
  1043.                                       if offset2 > 0
  1044.                                        then
  1045.                                         begin
  1046.                                          tempStr := TextToStr(hDest,offset1,
  1047.                                                              offset2);
  1048.                                          GetDItem(entrDLog,CurrentEItem,
  1049.                                                  itemType,item,box);
  1050.                                          SetIText(item,tempStr);
  1051.                                          CurrentEItem := CurrentEItem+2;
  1052.                                          offset1 := offset2+1;
  1053.                                         end
  1054.                                        else
  1055.                                         begin
  1056.                                          templ := TEFromScrap;
  1057.                                          DlgPaste(FrontWindow);
  1058.                                         end;                           
  1059.                                      until ((offset1 >=  scrapSize) or
  1060.                                             (offset2 < 0));
  1061.                                     end
  1062.                                   end;
  1063.                        clearItem: begin
  1064.                                    DlgDelete(FrontWindow);
  1065.                                    templ := TEToScrap;
  1066.                                   end;
  1067.                       end;
  1068.         dataMenuID : begin
  1069.                        HitOk;
  1070.                        case mItem of
  1071.                          AddRecItem : AddRecord;
  1072.                          DelRecItem : DelRecord;
  1073.                          LIstVItem  : ListView;
  1074.                        end;
  1075.                      end;
  1076.         srchMenuID : case mItem of
  1077.                        FirstItem : DoFirstSearch;
  1078.                        LastItem  : DoLastSearch;
  1079.                        NextItem  : DoNextSearch;
  1080.                        PrevItem  : DoPrevSearch;
  1081.                        SOnItem   : DoSearchOn;
  1082.                      end;
  1083.       end; (* case *)
  1084.      HiLiteMenu(0);
  1085.     end;
  1086.         
  1087.     procedure DoMouse;
  1088.     var    whichWindow     : WindowPtr;
  1089.             whichControl     : ControlHandle;
  1090.             pt              : point;
  1091.             part                : integer;
  1092.             r                    : rect;
  1093.             pp                    : ProcPtr;
  1094.     begin (* Do Mouse *)
  1095.      case FindWindow(event.where, whichWindow) of
  1096.         inDesk      : ;
  1097.         inMenuBar   : DoMenu(False);
  1098.         inSysWindow : SystemClick(event, whichWindow);
  1099.         inContent   : begin
  1100.                        SelectWindow(whichWindow);
  1101.                        if whichWindow = LView then 
  1102.                                begin
  1103.                                  SetPort(LView);
  1104.                                  GlobalToLocal(event.where);
  1105.                                  part := FindControl(event.where,whichWindow,whichControl);
  1106.                                  if Boolean(whichControl) then
  1107.                                   begin
  1108.                                    if (part = inThumb) then
  1109.                                      begin
  1110.                                        if (whichControl <> LVScrollBar) then
  1111.                                          begin
  1112.                                           part := TrackControl(whichControl,event.where,Nil);
  1113.                                           r := LView^.portRect;
  1114.                                           r.bottom := r.bottom-16;
  1115.                                           EraseRect(r);
  1116.                                           InvalRect(r);
  1117.                                          end;
  1118.                                      end
  1119.                                     else
  1120.                                      begin
  1121.                                       pp := @LHScrollControl;
  1122.                                       if whichControl = LVScrollBar then pp := @LVScrollControl;
  1123.                                       part := TrackControl(whichControl,event.where,Ptr(pp));
  1124.                                      end;
  1125.                                   end;
  1126.                                 end;
  1127.                       end;
  1128.         inDrag      : DragWindow(whichWindow, event.where, brect);
  1129.           inGoAway      : begin
  1130.                                   if TrackGoAway(whichWindow,event.where) then
  1131.                                  begin
  1132.                                   DisposeWindow(LView);
  1133.                                   LView := WindowPtr(0);
  1134.                                  end;
  1135.                              end;
  1136.        end; (* case *)
  1137.     end; (* Do Mouse *)
  1138.     
  1139.     procedure DoKey;
  1140.     begin
  1141.      if Boolean(event.modifiers and cmdKey) then DoMenu(True);
  1142.     end;
  1143.     
  1144.     procedure DoUpDate;
  1145.     begin
  1146.      if WindowPtr(event.message) = LView then
  1147.         LDrawWindow
  1148.     end;
  1149.     
  1150.     procedure DoAct;
  1151.     begin
  1152.     end;
  1153.     
  1154.     procedure HitButton(wItemHit : integer);
  1155.  
  1156.         procedure HitCanButton;
  1157.         var tempRec : CustRec;
  1158.             tempStr : LongIntStr;
  1159.             DataF   : Longint;
  1160.         begin
  1161.          CopyRecFromDLog(tempRec);
  1162.          with tempRec do
  1163.           begin
  1164.            if CustCode = 0 then 
  1165.             AddRecord
  1166.            else
  1167.             begin
  1168.              tempStr := LongToStr(CustCode);
  1169.              FindKey(CodeIndx, DataF, tempStr);
  1170.              if OK then
  1171.               begin
  1172.                GetRec(CustFile,DataF,tempRec);
  1173.                UpDateRecordOnDLOG(tempRec);
  1174.               end;
  1175.             end;
  1176.           end;
  1177.         end;
  1178.         
  1179.     begin (* HitButton *)
  1180.      case wItemHit of
  1181.         OKButton    : HitOK;
  1182.         CanButton   : HitCanButton;
  1183.      end;
  1184.     end; (* HitButton *)
  1185.     
  1186.     
  1187.     function DEvent : Boolean;
  1188.     var temp        : boolean;
  1189.         tempWindow  : WindowPtr;
  1190.         tempint     : integer;
  1191.     begin
  1192.      if Boolean(event.modifiers and cmdKey) then begin
  1193.                                                   DEvent := False;
  1194.                                                   Exit;
  1195.                                                  end;
  1196.      temp := IsDialogEvent(event);
  1197.      DEvent := temp;
  1198.      if temp then
  1199.        with event do
  1200.          begin
  1201.           if (what = keyDown) then
  1202.            begin
  1203.             if (message and charCodeMask) = returnKey then
  1204.              begin              (* Make pressing the return key look like the*)
  1205.               what := nullEvent;(* user hit the OK button                    *)
  1206.               if FrontWindow = entrDLog then 
  1207.                begin
  1208.                 HiliteControl(ENOKButtonHD,1);
  1209.                 HitButton(OKButton);
  1210.                 HiliteControl(ENOKButtonHD,0);
  1211.                end
  1212.               else
  1213.                begin
  1214.                 HiliteControl(SROKButtonHD,1);
  1215.                 HitSearchBox(OKButton);
  1216.                 HiliteControl(SROKButtonHD,0);
  1217.                end;
  1218.              end;
  1219.            end;
  1220.           if DialogSelect(event,whichDlog,wItemHit) then
  1221.            if (whichDLog = entrDLog) then
  1222.             begin
  1223.              if (what = keyDown) then DLOGDirty := True;
  1224.              if (wItemHit <= CanButton) then HitButton(wItemHit);
  1225.             end
  1226.            else
  1227.             if (whichDLog = srchDLog) then
  1228.              begin
  1229.               HitSearchBox(wItemHit);
  1230.              end;
  1231.          end
  1232.     end;
  1233.     
  1234. procedure SetUp;
  1235. Var itemType : integer;
  1236.     item     : Handle;
  1237.     box      : Rect;
  1238.     templ    : longint;
  1239.     
  1240.     procedure InitMangers;
  1241.     begin
  1242.      InitGraf(@thePort);
  1243.      InitFonts;
  1244.      InitWindows;
  1245.      InitMenus;
  1246.      TEInit;
  1247.      InitDialogs(Nil);
  1248.      InitCursor;
  1249.      FlushEvents(everyEvent,0);
  1250.      MoreMasters;
  1251.      MoreMasters;
  1252.      MaxApplZone;
  1253.     end;
  1254.     
  1255.     procedure PutUpMenus;
  1256.     var x : integer;
  1257.     begin
  1258.      for x := 1 to MenuCnt do
  1259.       begin
  1260.        MenuList[x] := GetMenu(applMenuID+x-1);
  1261.        if boolean(MenuList[x]) then InsertMenu(MenuList[x],0);
  1262.       end;
  1263.      AddResMenu(MenuList[1],'DRVR');
  1264.      DrawMenuBar;
  1265.     end;
  1266.     
  1267.     procedure InitDataBase;
  1268.     begin
  1269.      InitCustDatabase;
  1270.     end;
  1271.  
  1272.     procedure PutUpDialog;
  1273.     begin
  1274.      entrDLog := GetNewDialog(entrDLogID,nil,Pointer(0));
  1275.      if not boolean(entrDLog) then Die;
  1276.      srchDLog := GetNewDialog(srchDLogID,nil,Pointer(0));
  1277.      if not boolean(entrDLog) then Die;
  1278.      (* push last name button *)
  1279.      GetDItem(srchDLog,LNameSearch,itemType,item,box);
  1280.      SetCtlValue(ControlHandle(item),1);
  1281.      SetPort(entrDLog);
  1282.     end;
  1283.  
  1284. begin (* SetUp *)
  1285.  InitMangers;
  1286.  aboutBoxPtr := Pointer(0);
  1287.  DoAboutBox;
  1288.  PutUpMenus;
  1289.  InitDataBase;
  1290.  PutUpDialog;
  1291.  quit := false;
  1292.  AddRecord;
  1293.  
  1294.  brect := ScreenBits.bounds;
  1295.  insetRect(brect,4,4);
  1296.  
  1297.  GetDItem(entrDLog,OKButton,itemType,item,box);
  1298.  HNoPurge(item);
  1299.  ENOKButtonHD := ControlHandle(item);
  1300.  
  1301.  GetDItem(srchDLog,OKButton,itemType,item,box);
  1302.  HNoPurge(item);
  1303.  SROKButtonHD := ControlHandle(item);
  1304.  GetDItem(srchDLog,LNameSearch,itemType,item,box);
  1305.  HNoPurge(item);
  1306.  LNameButtonHD := ControlHandle(item);
  1307.  GetDItem(srchDLog,CustCodeSearch,itemType,item,box);
  1308.  HNoPurge(item);
  1309.  CustCodeButtonHD := ControlHandle(item);
  1310.  GetDItem(srchDLog,FindExact,itemType,item,box);
  1311.  HNoPurge(item);
  1312.  FindEButtonHD := ControlHandle(item);
  1313.  GetDItem(srchDLog,SearchText,itemType,item,box);
  1314.  HNoPurge(item);
  1315.  FindTextHD := ControlHandle(item);
  1316.  
  1317.  SIndx := @NameIndx;
  1318.  DLOGDirty := False;
  1319.  OldKeyN := '';
  1320.  mcount1 := 0;
  1321.  templ := ZeroScrap;
  1322.  LView := WindowPtr(0);
  1323.  KillAbout;
  1324. end; (* SetUp *)
  1325.  
  1326. begin
  1327.   SetUp;
  1328.   while not quit do
  1329.   begin
  1330.     CheckMenus;
  1331.     SystemTask;
  1332.     if GetNextEvent(everyEvent,event) then
  1333.     begin
  1334.       if not DEvent then 
  1335.        case event.what of
  1336.           nullEvent          : SystemTask;
  1337.           mouseDown          : DoMouse;
  1338.           keyDown,autoKey    : DoKey;
  1339.           updateEvt          : DoUpDate;
  1340.           activateEvt        : DoAct;
  1341.        end; { case }
  1342.     end
  1343.     else if DEvent then ;
  1344.   end;
  1345.   CleanUp;
  1346. end.
  1347.